package com.leoandroid.tool.toolsbox.largeread.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;

import com.leoandroid.tool.toolsbox.largeread.R;

public class WarningLightActivity extends BaseActivity{

    private View cautionTopMask;

    private View cautionBottomMask;
    private LinearLayout layoutClose;

    private static final int MSG_CAUTION_MASK_TOP = 1;
    private static final int MSG_CAUTION_MASK_BUTTON = 2;


    private static final int DELAY_TIME = 200;


    @SuppressLint("HandlerLeak")
    private Handler mhandler = new  Handler(){
        // 通过复写handlerMessage()从而确定更新UI的操作
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_CAUTION_MASK_TOP:
                    cautionTopMask.setVisibility(View.VISIBLE);
                    cautionBottomMask.setVisibility(View.GONE);
                    mhandler.sendEmptyMessageDelayed(MSG_CAUTION_MASK_BUTTON, DELAY_TIME);
                    break;
                case MSG_CAUTION_MASK_BUTTON:
                    cautionTopMask.setVisibility(View.GONE);
                    cautionBottomMask.setVisibility(View.VISIBLE);
                    mhandler.sendEmptyMessageDelayed(MSG_CAUTION_MASK_TOP, DELAY_TIME);
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_warning_light);
        initView();
        mhandler.sendEmptyMessageDelayed(MSG_CAUTION_MASK_TOP, DELAY_TIME);
    }

    private void initView(){
        cautionTopMask = findViewById(R.id.caution_top_mask);
        cautionBottomMask = findViewById(R.id.caution_bottom_mask);
        layoutClose = findViewById(R.id.layout_close);

        layoutClose.setOnClickListener(view -> {
            finish();
        });
    }
}
